// 例子53

function a() {
    async function f() {
        return await 123;
    }

    f().then(v => {
        console.log(v);
        console.log('----------------------------------');
        b()
    }) // 123
}


function b(){
    async function f() {
        await Promise.reject('出错了');
    }

    f()
        .then(v => console.log(v))
        .catch(e => {
            console.error(e); // Error: 出错了
            console.log('----------------------------------');
            c()
        })
}

function c(){
    async function f() {
        try {
            await Promise.reject('出错了');
        } catch(e) {
            console.error(e);
            console.log('----------------------------------');
            d();
        }

        await Promise.resolve('hello world'); // 没有try...catch的执行，这句不会执行
    }

    f() // Uncaught (in promise) 出错了

}

function d(){
    async function f() {
        try {
            await Promise.reject('出错了');
        } catch (e) {
            console.error(e)
        }

        return await Promise.resolve('hello world');
    }

    f()
        .then(v => {
            console.log(v); // "hello world"
            console.log('----------------------------------');
            g()
        })
}

function g(){
    async function f() {
        await Promise.reject('出错了')
            .catch(e => console.error(e)); // 出错了
        return await Promise.resolve('hello world');
    }

    f()
        .then(v => console.log(v)) // "hello world"
}

a()